package auth.controller;

import org.springframework.security.core.AuthenticatedPrincipal;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.annotation.CurrentSecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.OAuth2Token;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class HomeController {
    @GetMapping
    public Map<String, Object> home(
            @AuthenticationPrincipal OAuth2Token oAuth2Token,
            @CurrentSecurityContext Authentication authentication,
            @AuthenticationPrincipal AuthenticatedPrincipal authenticatedPrincipal) {
        Map<String, Object> model = CollectionUtils.newHashMap(5);
        model.put("oAuth2Token", oAuth2Token);
        model.put("authentication", authentication);
        model.put("authenticatedPrincipal", authenticatedPrincipal);
        model.put("SecurityContextHolder", SecurityContextHolder.getContext());
        return model;
    }
}